﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="java.io.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.nio.charset.Charset"%>
<%@ page import="java.util.regex.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String html = listFiles( request.getRealPath("/") );
%>

<%!
	public String listFiles(String path) {

		File file = new File(path);
		System.out.println(path);
		
		String html = "<div>";
		html += "<table >";
		html += "<tr role=\"head\"> <td sort=true>文件名 </td><td sort=true>大小 </td><td sort=true> 修改时间</td> </tr>";
		File[] sFiles = file.listFiles();
		
		Arrays.sort(sFiles, new Comparator<File>() {
			public int compare(File r1, File r2) {
				return r1.getName().compareTo(r2.getName());
			}
		});
		
		if(sFiles!=null){
			for(File f : sFiles){
				html += "<tr ><td><a href=\""+f.getName()+"\">" + f.getName() + "</a></td><td>" + f.length() + "</td><td>" + new Date(f.lastModified()) +"</td></tr>";
			}		
		}
		html +="</table></div>";
		

		return html;
	}%>

<head>
	<title>File List</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	 
	<script type="text/javascript" src="/jquery/jquery.1.9.1.min.js" ></script>	
	<script type="text/javascript" src="/jquery/TableSort.js" ></script>	

	<style>
		#mytable {   
		    padding: 0;
		    margin: 0;   
		    border-collapse:collapse;
		}
		table{
		}
		td {
		    border: 1px solid #C1DAD7;   
		    background: #fff;
		    font-size:11px;
		    padding: 6px 6px 6px 12px;
		    color: #4f6b72;
		}
		
		td.alt {
		    background: #F5FAFA;
		    color: #797268;
		}
	</style>
	

</head>

<body>

	<h1>File List</h1>
	<div>
		<%=html%>
	</div>
	
	<script>
	
			$("table").sorttable({
		            ascImgUrl: "/jquery/images/bullet_arrow_up.png",
		            descImgUrl: "/jquery/images/bullet_arrow_down.png",
		            ascImgSize: "8px",
		            descImgSize: "8px",
		            onSorted: function (cell) {
// 		               alert(cell.index() + " -- " + $.trim(cell.text()));
		            }
		        });
		        
	</script>

</body>